import { createQuickProject } from '../../api/pay'
import user from '../../../utils/user'
import { confirm,toast } from '../../../utils/util'
Page({
    data: {
        charge: '',
        chargeId: '',
        chargePhone: '',
        resident: '',
        residentId: '',
        typeName:0
    },
    onLoad(options){
        console.log(options,'options')
        this.setData({
            typeName:options.type
        })
    },
    onCharge(){
        wx.navigateTo({
            url: '/pages/team-list/team-list?select=selectCharge&type=radio',
        })
    },
    selectCharge(event){
        console.log(event,'eventevent')
        this.setData({
            charge: event[0].name,
            chargePhone: event[0].phone,
            chargeId: event[0].id,
        })
    },
    onResident(){
        wx.navigateTo({
            url: '/pages/team-list/team-list?select=selectResident',
        })
    },
    selectResident(event){
        console.log(event,'event')
        let id = [],name = ''
        event.forEach(item=>{
            id.push(item.id)
            name += item.name + ' '
        })
        this.setData({
            resident: name,
            residentId: id,
        })
        console.log(this.data.residentId,'residentId')
    },
    onCreate(){
        if(!this.data.charge){
            toast('请选择负责人')
            return
        }
        if(this.data.residentId.length === 0){
            toast('请至少选择一位驻厂')
            return
        }
        if(this.data.typeName === "1"){
            confirm('确定修改吗').then(res=>{
                createQuickProject({
                    contacts: this.data.charge,
                    phone: this.data.chargePhone,
                    projectLeader:this.data.residentId
                }).then(()=>{
                    user.quickProject = 1
                    wx.redirectTo({
                        url: '/packagePay/pages/fast-pay/fast-pay',
                    })
                })
            })
            return
        }
        createQuickProject({
            contacts: this.data.charge,
            phone: this.data.chargePhone,
            projectLeader:this.data.residentId
        }).then(()=>{
            user.quickProject = 1
            wx.redirectTo({
                url: '/packagePay/pages/fast-pay/fast-pay',
            })
        })
        
    }
})